﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class OrderStatusBus
    {
        private OrderStatusDao dao;
        public OrderStatusBus()
        {
            dao = new OrderStatusDao();
        }

        public bool insert(OrderStatus orderStatus) {
            return dao.insert(orderStatus);
        }

        public bool update(OrderStatus orderStatus) {
            return dao.update(orderStatus);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public OrderStatus get(int id) {
            DataTable dt = dao.get(id);
            OrderStatus orderStatus = new OrderStatus();

            if (dt.Rows.Count > 0)
            {
                orderStatus.Id = Convert.ToInt32(dt.Rows[0]["OST_ID"]);
                orderStatus.Name = dt.Rows[0]["OST_NAME"].ToString();
                orderStatus.Desc = dt.Rows[0]["OST_DESC"].ToString();
            }
            return orderStatus;
        }

        public List<OrderStatus> getAll() {
            DataTable dt = dao.getAll();
            List<OrderStatus> list = new List<OrderStatus>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    OrderStatus orderStatus = new OrderStatus();
                    orderStatus.Id = Convert.ToInt32(dr["OST_ID"]);
                    orderStatus.Name = dr["OST_NAME"].ToString();
                    orderStatus.Desc = dr["OST_DESC"].ToString();

                    list.Add(orderStatus);
                }

            }
            return list;
        }
    }
}
